//
//  UIButton+extension.swift
//  ERecycle-Shop
//
//  Created by abb on 16/8/15.
//  Copyright © 2016年 abb. All rights reserved.
//

import Foundation
extension UIButton {
    convenience init(imageName:String,bgColor:UIColor) {
        self.init()
        setImage(UIImage(named: imageName), forState: .Normal)
        
    }
    convenience init(title:String,titleColor:UIColor,fontSize:CGFloat,bgColor:UIColor) {
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(titleColor, forState: .Normal)
        setBackgroundImage(UIImage.imageWithColor(bgColor, size: CGSize(width: 10, height: 10)), forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
    class func buttonWithColorAndBorder(title:String) -> UIButton {
        let btn = UIButton()
        btn.backgroundColor = UIColor(red: 194/255.0, green: 245/255.0, blue: 180/255.0, alpha: 1)
        btn.setTitle(title, forState: .Normal)
        let colorSpace = CGColorSpaceCreateDeviceRGB()
        let colorref = CGColorCreate(colorSpace, [236, 229, 192, 1])
        btn.layer.borderColor = colorref
        btn.layer.borderWidth = 2
        btn.layer.cornerRadius = 2
        btn.layer.masksToBounds = true
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        return btn
    }
    
    class func buttonWithColor(title:String) -> UIButton {
        let btn = UIButton()
        btn.backgroundColor = UIColor.tintColor()
        btn.setTitle(title, forState: .Normal)
        btn.layer.cornerRadius = 5
        btn.layer.masksToBounds = true
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        return btn
    }
    class func buttonWithColor(title:String,red:CGFloat,green:CGFloat,blue:CGFloat) -> UIButton {
        let btn = UIButton()
        btn.backgroundColor = UIColor(red: red/255.0, green: green/255.0, blue: blue/255.0, alpha: 1)
        btn.setTitle(title, forState: .Normal)
        btn.layer.cornerRadius = 4
        btn.layer.masksToBounds = true
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        return btn
    }
}